package cn.iocoder.yudao.module.member.service.device;

import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.member.controller.admin.device.recrod.MemberDeviceRecordPageReqVO;
import cn.iocoder.yudao.module.member.controller.app.device.vo.AppMemberDeviceRecordPageReqVO;
import cn.iocoder.yudao.module.member.dal.dataobject.device.MemberDeviceRecordDO;
import cn.iocoder.yudao.module.member.dal.dataobject.point.MemberPointRecordDO;
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
import cn.iocoder.yudao.module.member.dal.mysql.device.MemberDeviceRecordMapper;
import cn.iocoder.yudao.module.member.enums.ErrorCodeConstants;
import cn.iocoder.yudao.module.member.enums.point.MemberPointBizTypeEnum;
import cn.iocoder.yudao.module.member.service.user.MemberUserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Set;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;


/**
 * 积分记录 Service 实现类
 *
 * @author QingX
 */
@Slf4j
@Service
@Validated
public class MemberDeviceRecordServiceImpl implements MemberDeviceRecordService {

    @Resource
    private MemberDeviceRecordMapper memberDeviceRecordMapper;

    @Override
    public PageResult<MemberDeviceRecordDO> getDeviceRecordPage(MemberDeviceRecordPageReqVO pageReqVO) {
        // 执行查询
        return memberDeviceRecordMapper.selectPage(pageReqVO);
    }

    @Override
    public PageResult<MemberDeviceRecordDO> getDeviceRecordPage(Long userId, AppMemberDeviceRecordPageReqVO pageReqVO) {
        return memberDeviceRecordMapper.selectPage(userId, pageReqVO);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createDeviceRecord(Long userId, Integer device, MemberPointBizTypeEnum bizType, String bizId,Integer totalDevice,Integer totalDeviceFront,Integer timeOut,String version,String udid) {

            MemberDeviceRecordDO record = new MemberDeviceRecordDO()
                    .setUserId(userId).setBizId(bizId).setBizType(bizType.getType())
                    .setTitle(bizType.getName()).setDescription(StrUtil.format(bizType.getDescription(), device))
                    .setDevice(device).setTotalDevice(totalDevice)
                    .setTotalDeviceFront(totalDeviceFront).setFlag(bizType.isAdd())
                    .setUdid(udid).setVersionTypeName(version).setTimeOut(timeOut);
            memberDeviceRecordMapper.insert(record);
        }


}
